<!-- 采购管理-基础设置-供应商评级设置 -->
<template>
  <div>
    <PageHeader :title="title" :breadCrumb="breadCrumb" :show-back="true">
      <template #buts>
        <a-button type="primary" @click="save">保存</a-button>
        <a-button @click="cancel">取消</a-button>
      </template>
    </PageHeader>
    <LevelSetting
      ref="levelSettingRef"
      :setting-info="info.list"
      :type="info.type"
    ></LevelSetting>
  </div>
</template>

<script lang="ts" setup>
  import { reactive, ref } from 'vue';
  import { useRouter } from 'vue-router';
  import {
    GetSupplierRateInfo,
    PostSupplierRateInfo,
  } from '@/api/buy-management/supplier-management/base-setting';

  const router = useRouter();
  const title: string = '供应商评级设置';

  const breadCrumb: string[] = [
    '采购管理',
    '供应商管理',
    '供应商设置',
    '供应商评级设置',
  ];

  let levelSettingRef = ref(); // 储存组件的ref
  const info: any = reactive({
    list: [],
    type: 5,
  });

  const getData = async () => {
    try {
      const { data, type } = await GetSupplierRateInfo();
      info.list = data.length <= 0 ? [{ name: '', default: '' }] : data;
      info.type = type;
    } catch (err: unknown) {
      console.log(err);
    }
  };
  getData();
  // 保存
  const save = async () => {
    try {
      const data: any = [];

      levelSettingRef.value.currSettingInfo.forEach((element: any) => {
        data.push({
          ...element,
          // name: element.name,
          // details: element.details,
        });
      });
      await PostSupplierRateInfo({
        data,
        ids: levelSettingRef.value.delIds,
      });
      getData();
      levelSettingRef.value.isEdit = false;
    } catch (err: unknown) {
      console.log(err);
    }
  };

  const cancel = () => {
    router.back();
  };
</script>

<style scoped lang="less"></style>
